package edu.bw.mapper;

import edu.bw.po.OrderDetail;
import edu.bw.po.Product;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface OrderDetailMapper {

    /**
     * 根据订单id查询订单明细
     *
     * @param orderId 订单id
     * @return
     */
    //@Select("SELECT order_id,product_id,product_num FROM mybatis02.order_detail WHERE order_id= #{orderId}")
    @Results({
            @Result(column = "product_id", property = "productId"),
            @Result(property = "product", javaType = Product.class, column = "product_id",
                    one = @One(select = "edu.bw.mapper.ProductMapper.findById", fetchType = FetchType.LAZY))
    })
    @Select("SELECT order_id,product_id,product_num FROM mybatis02.order_detail WHERE order_id= #{orderId}")
    List<OrderDetail> findOrderDetailByOrderId(int orderId);
}
